<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>聊天记录</title>
    <base th:href="${#request.getContextPath()}+'/'">
    <link rel="stylesheet" type="text/css" href="/admin/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="/admin/js/layui/layim/dist/layim-assets/layim.css" media="all">
    <style>
        body .layim-chat-main{height: auto;}
    </style>
</head>
<body class="childrenBody">
<input type="hidden" th:value="${fromUserId}" id="fromUserId">
<input type="hidden" th:value="${toUserId}" id="toUserId">
<div class="layui-body">
    <!-- 内容主体区域 -->
    <div style="padding: 30px;">
        <div class="layim-chat-main">
            <ul id="LAY_view"></ul>
        </div>
    </div>
</div>
<textarea title="消息模版" id="LAY_tpl" style="display:none;">
    {{# layui.each(d.data, function(index, item){
      if(item.fromUserId == d.fromUserId){ }}
        <li class="layim-chat-mine">
            <div class="layim-chat-user">
                <img src="{{ item.sendPortraitUri }}">
                <cite><i>{{ item.createTime }}</i>{{ item.sendName }}</cite>
            </div>
                {{# if(item.objectName == "RC:TxtMsg"){ }}
                  <div class="layim-chat-text">{{ item.text }}</div>
                {{# } else { }}
                  <div  style="width: 35%;height: 30%;" class="layim-chat-text"><img src="{{ item.content }}" /></div>
                {{# } }}
        </li>
      {{# } else { }}
        <li>
            <div class="layim-chat-user">
                <img src="{{ item.receiverPortraitUri }}">
                <cite>{{ item.sendName }}<i>{{item.createTime}}</i></cite>
            </div>
              {{# if(item.objectName == "RC:TxtMsg"){ }}
                  <div class="layim-chat-text">{{ item.text }}</div>
                {{# } else { }}
                    <div style="width: 35%;height: 30%;" class="layim-chat-text"><img src="{{ item.content }}" /></div>
                {{# } }}
        </li>
      {{# }
    }); }}
</textarea>
</div>
<script src="/admin/js/layui/layui.js"></script>
<script>
    layui.config({
        base: '/admin' //静态资源所在路径
    }).extend({
        index: '/js/lib/index' //主入口模块
    }).use(['jquery','laytpl','index'], function(){
        var laytpl = layui.laytpl
            ,$ = layui.jquery
        var fromUserId = $('#fromUserId').val();

        // 获取父级页面元素和 iframe 元素的引用
        var parent = window.parent.document;
        var iframe = parent.getElementById('mainFrame');
        // 获取父级页面的高度
        var parentHeight = parent.documentElement.clientHeight;
        // 设置 iframe 的高度为父级页面高度的 80%
        iframe.style.height = (parentHeight * 0.8) + 'px';




        //开始请求聊天记录
        layui.admin.req({
            url:layui.setter.contextPath  + '/message/person/singleChatRecord',
            type:'post',
            data:{
                fromUserId: $("#fromUserId").val(),
                toUserId: $("#toUserId").val(),
            },
            done:function(resDate) {
                var html = laytpl(LAY_tpl.value).render({
                    data: resDate.data,
                    fromUserId: fromUserId
                });
                $('#LAY_view').html(html);
            }
        });
    });
</script>
</body>
</html>
